package com.xixi.core.rpc.protocol;

import lombok.Getter;

/**
 * @author: zxh
 * @date: 2024/8/26 10:55
 * @description: 协议消息的类型枚举
 */
@Getter
public enum ProtocolMessageTypeEnum {

	REQUEST(0),
	RESPONSE(1),
	HEART_BEAT(2),
	OTHERS(3);

	private final int key;

	ProtocolMessageTypeEnum(int key) {
		this.key = key;
	}

	/**
	 * 根据可以获取枚举值
	 * @param key 消息类型key
	 * @return 返回对应的枚举值
	 */
	public static ProtocolMessageTypeEnum getEnumByKey(int key) {
		for (ProtocolMessageTypeEnum anEnum : ProtocolMessageTypeEnum.values()) {
			if (anEnum.key == key) {
				return anEnum;
			}
		}
		return null;
	}


}
